package com.zimmor.controller;

/**
 * @Author:zimmor
 * @Date: 2021/4/16 22:47
 * @Description
 * @version: 1.0.0
 */

import com.zimmor.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.handler.UserRoleAuthorizationInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class Controller {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Autowired
    private HttpServletRequest request;
    @GetMapping("/test")
    public String test(HttpServletRequest request) {
        int i = 0;
        i = i +2;
        int a =2;
        i = 1 + a;
        System.out.println("i=" + i);
        HttpSession session = request.getSession();
        session.setAttribute("username", "zhangsan");
        System.out.println("开始时间" + simpleDateFormat.format(new Date()));
        return "测试";
    }
    @GetMapping("/test2")
    public String test2() {
        Object username = request.getSession().getAttribute("username");
        System.out.println("username" + username);
        System.out.println("结束时间" + simpleDateFormat.format(new Date()));
        return "测试2";
    }
    @PostMapping("/test3")
    public String test3(@RequestParam String name, @RequestParam String age) {

        System.out.println("username" + name);
        System.out.println("age = " + age);
        return "测试3";
    }
    @PostMapping("/test4")
    public String test4(@RequestBody User user) {

        System.out.println("username" + user.getName());
        System.out.println("user.getAge() = " + user.getAge());
        return "测试4";
    }
}
